﻿@inherits DynamicInputBase

@if (IsSelect)
{
    <SelectInput Id=@UseId Status=@Status TValue="string" Input=@Input
        @bind-Value="Value" class=@(Input?.Css?.Input) LabelClass=@(Input?.Css?.Label) Help=@TextUtils.Humanize(UseId) @attributes="AllAttributes" />
}
else if (IsCheckbox)
{
    <CheckboxInput Id=@UseId Status=@Status @bind-Value="Value" class=@(Input?.Css?.Input) LabelClass=@(Input?.Css?.Label) Help=@UseHelp @attributes="AllAttributes" />
}
else if (UseType == "file")
{
    string? value = null;
    ICollection<string>? values = null;
    UploadedFile? file = null;
    List<UploadedFile>? files = null;

    if (ValueObject != null)
    {
        value = ValueObject as string;
        if (value == null)
        {
            values = ValueObject as ICollection<string>;
            if (values == null)
            {
                if (ValueObject is System.Collections.IEnumerable)
                {
                    files = ValueObject.ConvertTo<List<UploadedFile>>();
                }
                else
                {
                    file = ValueObject.ConvertTo<UploadedFile>();
                }
            }
        }
    }

    <FileInput type=@UseType Id=@UseId Status=@Status class=@(Input?.Css?.Input) LabelClass=@(Input?.Css?.Label) Help=@UseHelp @attributes="AllAttributes"
        Multiple=@(Input?.Multiple ?? false) Accept=@(Input?.Accept)
        Value=@value Values=@values File=@file Files=@files
        OnInput="e => Model[Input!.Id] = e" />
}
else if (UseType == "tag")
{
    <TagInput Id=@UseId Status=@Status @bind-Value="Values" class=@(Input?.Css?.Input) LabelClass=@(Input?.Css?.Label) Help=@UseHelp @attributes="AllAttributes" />
}
else
{
    <TextInput type=@UseType Id=@UseId Status=@Status @bind-Value="Value" class=@(Input?.Css?.Input) LabelClass=@(Input?.Css?.Label) Help=@UseHelp @attributes="AllAttributes" />
}
